from apps.common.base.views import *
from apps.interface.pageConfig.serializers import *
from apps.interface.pageConfig.dao import PageConfigDao
from apps.interface.pageConfig.filters import PageConfigFilter
from apps.interface.page.dao import PageDao
from apps.interface.client.dao import ClientDao

class BasePageConfigViewSet(BaseViewSet):
    serializer_class = PageConfigModelSerializer
    filter_class = PageConfigFilter
    DAO_CLASS = PageConfigDao

    @action(methods=['post'], detail=False)
    def createAction(self, request):
        params = getRequestParams(self.request)
        # 设置默认自定义页面和客户端
        # page_custom = PageDao().findAll().filter(name='custom').first()
        # params['pagee'] = page_custom.id
        clients = ClientDao().findAll()
        params['clients'] = list(clients.values_list('id', flat=True))
        # params['key'] = 'custom'
        print('params', params)
        self.DAO_CLASS().create(params)
        return Response(response_success('新增成功'))